package com.gitee.wsl.struct.dict

import com.gitee.wsl.data.store.StoreServer
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

class DictionaryVer<T : Any,K:Any>(val state: StoreServer, private val dictName:String, private val keyGet:()->T):
    ReadOnlyProperty<Any, K> {

    override fun getValue(thisRef: Any, property: KProperty<*>): K {
        val dict = DictionaryExt.getDictionary<T, K>(state, dictName)
        val key = keyGet.invoke()
        return dict.get(key)?:throw Exception("Get dictionary:$dictName value with key: $key")
    }

}